//
//  GoodsDetailSpecificationsTableViewCell.m
//  much
//
//  Created by weijunjie on 2019/1/7.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "GoodsDetailSpecificationsTableViewCell.h"
#import "GoodsModel.h"
static NSString *GoodsDetailSpecificationsTableViewCellIdentifier = @"GoodsDetailSpecificationsTableViewCellIdentifier";
@interface GoodsDetailSpecificationsTableViewCell ()
@property (nonatomic, strong) UIView *topLineView; // 顶部线条
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *moreLabel; // 更多

@end
@implementation GoodsDetailSpecificationsTableViewCell

+ (instancetype)detailSpecificationsTableViewCellWithTableView:(UITableView *)tableView {
    GoodsDetailSpecificationsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:GoodsDetailSpecificationsTableViewCellIdentifier];
    if (!cell) {
        cell = [[GoodsDetailSpecificationsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:GoodsDetailSpecificationsTableViewCellIdentifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)setModel:(GoodsModel *)model {
    _model = model;
    if (model.selectedStandardName.hasValue) {
        self.titleLabel.text = [NSString stringWithFormat:@"已选: %@",model.selectedStandardName];
    } else {
        self.titleLabel.text = @"选择 规格";
    }
}

#pragma mark - 懒加载
- (UIView *)topLineView {
    if (!_topLineView) {
        _topLineView = [[UIView alloc] init];
        _topLineView.backgroundColor = Color244;
        [self.contentView addSubview:_topLineView];
        [_topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(self.contentView);
            make.height.mas_equalTo(10);
        }];
    }
    return _topLineView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = APPFONT(14);
        _titleLabel.textColor = Color34;
        [self.contentView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topLineView.mas_bottom);
            make.left.equalTo(self.contentView).offset(15);
            make.right.equalTo(self.moreLabel).offset(-15);
            make.bottom.equalTo(self.contentView);
        }];
    }
    return _titleLabel;
}

- (UILabel *)moreLabel {
    if (!_moreLabel) {
        _moreLabel = [UILabel new];
        _moreLabel.textColor = Color140;
        _moreLabel.text = N_MORE;
        _moreLabel.font = ICONFONT(14);
        [self.contentView addSubview:_moreLabel];
        [_moreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).with.offset(- 15);
            make.top.equalTo(self.topLineView.mas_bottom);
            make.bottom.equalTo(self.contentView);
        }];
    }
    return _moreLabel;
}

@end
